package com.flynn.rock.crm.repository;

import com.flynn.rock.crm.entity.CrmConfigEntity;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.Optional;

@Repository
public interface CrmConfigRepository extends JpaRepository<CrmConfigEntity, Long> {

    String AutoDispatchOrderConfigKey = "AutoDispatchOrderConfig";

    default Optional<CrmConfigEntity> getCrmConfigEntity(String configKey) {
        CrmConfigEntity entity = new CrmConfigEntity();
        entity.setConfigKey(configKey);
        ExampleMatcher matcher = ExampleMatcher.matching().withMatcher("configKey",
                        ExampleMatcher.GenericPropertyMatcher::exact);
        Example<CrmConfigEntity> example = Example.of(entity, matcher);
        return this.findOne(example);
    }
}
